package operation;

import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOPeration{

    public void work(BookList bookList){
        System.out.println("借阅图书!");
        System.out.println("输入你要借阅的书的名称");
        Scanner in = new Scanner(System.in);
        String obj = in.nextLine();
        int index = bookList.getUsedSize();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            if(bookList.getPos(i).getName().equals(obj)){
                System.out.println("信息如下："+bookList.getPos(i));
                index = i;
                break;
            }
        }
        if(index < bookList.getUsedSize()){
            bookList.getPos(index).setBorrowed(true);
            System.out.println("借阅成功");
        }else{
            System.out.println("要借阅的图书不存在");
        }
    }
}
